package com.leetcode.problems007;


/**
 * @Description
 * @Date 2021/11/20 14:34
 * @Author ghery
 * @Version V1.0
 */
public class Solution {


    public int reverse(int x) {
        boolean flag = true;
        if(x < 0 ){
            flag = false;
        }
        x = Math.abs(x);
        char str[] = String.valueOf(x).toCharArray();
        int l = 0;
        int r = str.length - 1;
        while(l < r){
            char temp = str[l];
            str[l] = str[r];
            str[r] = temp;
            l++;
            r--;
        }
        long res = flag?Long.valueOf(new String(str)) : (0 - Long.valueOf(new String(str))) ;
        if(res < Integer.MIN_VALUE || res > Integer.MAX_VALUE){
            return 0;
        }

        return (int)res;

    }

    public static void main(String[] args) {
        System.out.println(new Solution().reverse(-123));
    }
}
